﻿{% block js %}
    <script>
        $(document).ready(function () {
            $("select[name=term]").change(function () {
                var arg = {
                    url:"{% url mark_for_a_student class_id student_id %}/" + $(this).val(),
                    success:function (response) {
                        $('.ui-tabs-panel:visible').html(response);
                    },
                    global:false
                };
                $.ajax(arg);
            });
            {% if pos > 3 %}
                $.ajax({
                    url:"{% url cap_nhap_mien_giam class.id student.id %}",
                    global:false,
                    dataType:'html',
                    type:'GET',
                    success:function (response) {
                        $("#miengiam").html(response);
                        applyListener();
                    }
                });
            {% endif %}
        });
    </script>
{% endblock %}

{% block content %}
    {% load mark %}
    {% if message != None %}
        {{ message }}
    {% endif %}

    <div id="miengiam" class="span6">

    </div>


    <div class="form-header">
        <form action="{% url mark_for_a_student class_id student_id %}" name="info" method="post"
              id='myform'> {% csrf_token %}
            Bảng điểm học kỳ
            <select name="term">
                {% for term in termList %}
                    <option value={{ term.id }} selected> {{ term }} </option>
                {% endfor %}
            </select>
        </form>
        <div align="right">
            <a class="btn" href="{% url mark_excel_for_a_student class_id student_id  termChoice %}"> Xuất ra Excel</a>
        </div>
    </div>

    <table class="table table-bordered grid">
        <tr>
            <th rowspan=2 style="text-align: center;" width="10%">
                Học kỳ
            </th>
            <th colspan=2 style="text-align: center;" width="20%">
                Kết quả xết loại
            </th>
            {% ifequal selectedTerm.number 2 %}
                <th colspan=2 style="text-align: center;" width="20%">
                    Xếp loại lại sau KT lại môn học hoặc rèn luyện thêm về học lực
                </th>
            {% endifequal %}

        </tr>
        <tr>
            <th width="10%">
                TB
            </th>
            <th width="10%">
                HL
            </th>

            {% ifequal selectedTerm.number 2 %}
                <th width="10%">
                    TB
                </th>
                <th width="10%">
                    HL
                </th>
            {% endifequal %}
        </tr>
        <tr>
            <td style="text-align: center;">
                Học Kỳ I
            </td>
            <td style="text-align: center;">
                {{ tbhk1.tb_hk|floatformat:"-1" }}
            </td>
            <td style="text-align: center;">
                {{ tbhk1.hl_hk|convertHlToVietnamese }}
            </td>
            {% ifequal selectedTerm.number 2 %}
                <td>
                </td>
                <td>
                </td>
            {% endifequal %}
        </tr>
        {% ifequal selectedTerm.number 2 %}
            <tr>
                <td style="text-align: center;">
                    Học Kỳ II
                </td>
                <td style="text-align: center;">
                    {{ tbhk2.tb_hk|floatformat:"-1" }}
                </td>
                <td style="text-align: center;">
                    {{ tbhk2.hl_hk|convertHlToVietnamese }}
                </td>
                <td>
                </td>
                <td>
                </td>

            </tr>

            <tr>
                <td style="text-align: center;">
                    Cả năm
                </td>
                <td style="text-align: center;">

                    {{ tbCaNam.tb_nam|floatformat:"-1" }}
                </td>
                <td style="text-align: center;">
                    {{ tbCaNam.hl_nam|convertHlToVietnamese }}
                </td>
                <td>
                </td>
                <td>
                </td>

            </tr>
        {% endifequal %}

    </table>

    <script type="text/javascript">
        document.info.term.value = {{termChoice}}
    </script>


    <table class="table table-bordered grid">
        <tr>
            <th rowspan=2 width="4%">
                STT
            </th>
            <th rowspan=2 width="18%" class="align-left">
                Môn
            </th>
            <th rowspan=2 width="20%">
                Miệng
            </th>

            <th rowspan=2 width="20%">
                15 phút
            </th>
            <th rowspan=2 width="20%">
                45 phút
            </th>
            <th rowspan=2 width="5%">
                Thi cuối kì
            </th>
            {% ifequal selectedTerm.number 1 %}
                <th rowspan=2 width="5%">
                    TB
                </th>
            {% else %}
                <th colspan=3>
                    <b>ĐIỂM TRUNG BÌNH </b>
                </th>
            {% endifequal %}
        </tr>

        <tr>
            {% ifequal selectedTerm.number 2 %}
                <th class="align-left">HK I</th>
                <th class="align-left">HK II</th>
                <th class="align-left">CK</th>
            {% endifequal %}
        </tr>


        {% ifequal selectedTerm.number 1 %}
            {% for s,m,m1,m2,m3 in list %}
                <tr>
                    <td style="text-align: center;">
                        {{ forloop.counter }}
                    </td>
                    <td class="align-left">
                        {{ s }}
                    </td>
                    {% if m.mg %}
                        <td> MG</td>
                        <td> MG</td>
                        <td> MG</td>
                        <td> MG</td>
                        <td> MG</td>
                    {% else %}
                        <td>
                            {{ m1 }}
                        </td>
                        <td>
                            {{ m2 }}
                        </td>
                        <td>
                            {{ m3 }}
                        </td>
                        {% if not s.nx %}
                            <td align="right">
                                {{ m.ck|floatformat:"1" }}
                            </td>
                            <td align="right">
                                {{ m.tb|floatformat:"1" }}
                            </td>
                        {% else %}
                            <td style="text-align: center;">
                                {{ m.ck|convertMarkToCharacter }}
                            </td>
                            <td style="text-align: center;">
                                {{ m.tb|convertMarkToCharacter }}
                            </td>
                        {% endif %}
                        </tr>
                    {% endif %}
            {% endfor %}

        {% else %}
            {% for s,m,m1,m2,m3,hk1,tbnam in list %}
                <tr>
                    <td style="text-align: center;">
                        {{ forloop.counter }}
                    </td>
                    <td class="align-left">
                        {{ s }}
                    </td>
                    {% if m.mg %}
                        <td>MG</td>
                        <td>MG</td>
                        <td>MG</td>
                    {% else %}
                        <td>
                            {{ m1 }}
                        </td>
                        <td>
                            {{ m2 }}
                        </td>
                        <td>
                            {{ m3 }}
                        </td>
                    {% endif %}

                    {% if not s.nx %}

                        {% if m.mg %}
                            <td>MG</td>
                        {% else %}
                            <td align="right">
                                {{ m.ck|floatformat:"1" }}
                            </td>
                        {% endif %}

                        {% if hk1.mg %}
                            <td>MG</td>
                        {% else %}
                            <td align="right">
                                {{ hk1.tb|floatformat:"1" }}
                            </td>
                        {% endif %}

                        {% if m.mg %}
                            <td>MG</td>
                        {% else %}
                            <td align="right">
                                {{ m.tb|floatformat:"1" }}
                            </td>
                        {% endif %}

                        {% if tbnam.mg %}
                            <td>MG</td>
                        {% else %}
                            <td align="right">
                                {{ tbnam.tb_nam|floatformat:"1" }}
                            </td>
                        {% endif %}

                    {% else %}
                        {% if m.mg %}
                            <td>MG</td>
                        {% else %}
                            <td align="right">
                                {{ m.ck|convertMarkToCharacter }}
                            </td>
                        {% endif %}

                        {% if hk1.mg %}
                            <td>MG</td>
                        {% else %}
                            <td align="right">
                                {{ hk1.tb|convertMarkToCharacter }}
                            </td>
                        {% endif %}

                        {% if m.mg %}
                            <td>MG</td>
                        {% else %}
                            <td align="right">
                                {{ m.tb|convertMarkToCharacter }}
                            </td>
                        {% endif %}

                        {% if tbnam.mg %}
                            <td>MG</td>
                        {% else %}
                            <td align="right">
                                {{ tbnam.tb_nam|convertMarkToCharacter }}
                            </td>
                        {% endif %}
                    {% endif %}
                </tr>
            {% endfor %}
        {% endifequal %}

    </table>
{% endblock %}